package top.yvyan.guettable.baseFun;

import android.app.Activity;

import top.yvyan.guettable.Gson.ApplicationOTA;
import top.yvyan.guettable.R;
import top.yvyan.guettable.service.fetch.StaticService;
import com.azhon.appupdate.manager.DownloadManager;

/**
 * APP检查更新
 */
public class UpdateApp {
  /**
   * 检查软件更新
   *
   * @param activity activity
   * @param type     0 自动检查更新 1 手动检查更新
   */
  public static void checkUpdate(Activity activity, int type) {
    new Thread(()-> {
      ApplicationOTA otaInfo = StaticService.checkOTA(activity);
      if (otaInfo == null) return;
      DownloadManager manager = new DownloadManager.Builder(activity)
              .apkUrl(otaInfo.DownloadUrl)
              .apkName("appupdate.apk")
              .smallIcon(R.mipmap.ic_launcher)
              .apkVersionCode(otaInfo.VersionCode)
              .apkVersionName(otaInfo.VersionName)
              .apkSize(String.format("%.2fMB", (double)otaInfo.ApkSize/1024))
              .apkDescription(otaInfo.ModifyContent)
              .build();
      manager.download();
    }).start();
  }
}